home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / viewwrld / viewwrld.lha / viewworld / lgd / sunview / view.c < prev   
Encoding:
C/C++ Source or Header  |  1989-09-21  |  5.4 KB  |  206 lines

  1. /* $Id: view.c,v 1.7 89/09/20 18:00:10 mbp Exp $
  2.  *
  3.  * view.c: view control procedures for SunView
  4.  */
  5.  
  6. /************************************************************************
  7.  *        Copyright (C) 1989 by Mark B. Phillips                  *
  8.  *                                     *
  9.  * Permission to use, copy, modify, and distribute this software and    *
  10.  * its documentation for any purpose and without fee is hereby granted, *
  11.  * provided that the above copyright notice appear in all copies and    *
  12.  * that both that copyright notice and this permission notice appear in *
  13.  * supporting documentation, and that the name of Mark B. Phillips or   *
  14.  * the University of Maryland not be used in advertising or publicity   *
  15.  * pertaining to distribution of the software without specific, written *
  16.  * prior permission.  This software is provided "as is" without express *
  17.  * or implied warranty.                                                 *
  18.  ************************************************************************/
  19.  
  20. #include <math.h>
  21. #include <stdio.h>
  22. #include "../lgd.h"
  23. #include "../vector.h"
  24. #include GR_HEADER
  25.  
  26. /*--------------------------------------------------------------*/
  27. int
  28. gr_horizontal_sweep(angle)
  29.      double angle;
  30. {
  31.   lgd_View3 view;
  32.   double E[3], U[3], M[3][3], E1[3];
  33.   
  34.   lgd_inquire_view( &view );
  35.   LGD_sub_vec( E, view.eye, view.focus );
  36.   LGD_sub_vec( U, view.up,  view.focus );
  37.   LGD_compute_3d_rot_mat( M, U, -angle );
  38.   LGD_matmul_vec( E1, M, E );
  39.   LGD_add_vec( view.eye, view.focus, E1 );
  40.   lgd_set_view( &view );
  41.   lgd_update_display();
  42.   return(0);
  43. }
  44.  
  45. /*--------------------------------------------------------------*/
  46. int
  47. gr_vertical_sweep(angle)
  48.      double angle;
  49. {
  50.   lgd_View3 view;
  51.   double D[3], E[3], U[3], M[3][3], E1[3], U1[3];
  52.   
  53.   lgd_inquire_view( &view );
  54.   LGD_sub_vec( E, view.eye, view.focus );
  55.   LGD_sub_vec( U, view.up,  view.focus );
  56.   LGD_cross_vec( D, U, E );
  57.   LGD_compute_3d_rot_mat( M, D, angle );
  58.   LGD_matmul_vec( E1, M, E );
  59.   LGD_matmul_vec( U1, M, U );
  60.   LGD_add_vec( view.eye, view.focus, E1 );
  61.   LGD_add_vec( view.up, view.focus, U1 );
  62.   lgd_set_view( &view );
  63.   lgd_update_display();
  64.   return(0);
  65. }
  66.  
  67. /*--------------------------------------------------------------*/
  68. int
  69. gr_horizontal_pan(angle)
  70.      double angle;
  71. {
  72.   lgd_View3 view;
  73.   double F[3], U[3], D[3], F1[3], U1[3], M[3][3];
  74.   
  75.   lgd_inquire_view( &view );
  76.   LGD_sub_vec( F, view.focus, view.eye );
  77.   LGD_sub_vec( U, view.up, view.eye );
  78.   LGD_sub_vec( D, view.up, view.focus );
  79.   LGD_compute_3d_rot_mat( M, D, angle );
  80.   LGD_matmul_vec( F1, M, F );
  81.   LGD_matmul_vec( U1, M, U );
  82.   LGD_add_vec( view.focus, view.eye, F1 );
  83.   LGD_add_vec( view.up, view.eye, U1 );
  84.   lgd_set_view( &view );
  85.   lgd_update_display();
  86.   return(0);
  87. }
  88.  
  89. int
  90. gr_vertical_pan(angle)
  91.      double angle;
  92. {
  93.   lgd_View3 view;
  94.   double F[3], U[3], D[3], F1[3], U1[3], M[3][3];
  95.   
  96.   lgd_inquire_view( &view );
  97.   LGD_sub_vec( F, view.focus, view.eye );
  98.   LGD_sub_vec( U, view.up, view.eye );
  99.   LGD_cross_vec( D, U, F );
  100.   LGD_compute_3d_rot_mat( M, D, angle );
  101.   LGD_matmul_vec( U1, M, U );
  102.   LGD_matmul_vec( F1, M, F );
  103.   LGD_add_vec( view.focus, view.eye, F1 );
  104.   LGD_add_vec( view.up, view.eye, U1 );
  105.   lgd_set_view( &view );
  106.   lgd_update_display();
  107.   return(0);
  108. }
  109.  
  110. int
  111. gr_tilt(angle)
  112. double angle;
  113. {
  114.   lgd_View3 view;
  115.   double E[3], U[3], M[3][3], U1[3];
  116.   
  117.   lgd_inquire_view( &view );
  118.   LGD_sub_vec( E, view.eye, view.focus );
  119.   LGD_sub_vec( U, view.up,  view.focus );
  120.   LGD_compute_3d_rot_mat( M, E, angle );
  121.   LGD_matmul_vec( U1, M, U );
  122.   LGD_add_vec( view.up, view.focus, U1 );
  123.   lgd_set_view( &view );
  124.   lgd_update_display();
  125.   return(0);
  126. }
  127. /*--------------------------------------------------------------*/
  128. int
  129. gr_perspective(factor)
  130. double factor;
  131. {
  132.   lgd_View3 view;
  133.   double fdist, D[3];
  134.  
  135.   lgd_inquire_view( &view );
  136.   fdist = factor*LGD_L2dist_vec( view.eye, view.focus );
  137.   LGD_sub_vec( D, view.eye, view.focus );
  138.   LGD_unit_vec( D );
  139.   LGD_scamul_vec( D, fdist, D );
  140.   LGD_add_vec( view.eye, view.focus, D );
  141.   lgd_set_view( &view );
  142.   lgd_update_display();
  143.   return(0);
  144. }
  145.  
  146. /*--------------------------------------------------------------
  147.  * Function:     gr_zoom
  148.  * Description:  changes size of view plane window
  149.  * Arguments IN: zoom_factor
  150.  * Returns:      nothing
  151.  * Notes:        multiplies length and width of view plane window
  152.  *         by zoom_factor; keeps center of window fixed.
  153.  */
  154. int
  155. gr_zoom( zoom_factor )
  156. double zoom_factor;
  157. {
  158.   lgd_View3 view;
  159.   double u_len_2, v_len_2, u_cen, v_cen;
  160.     
  161.   lgd_inquire_view( &view );
  162.   u_cen = (view.u1 + view.u2) / 2;
  163.   v_cen = (view.v1 + view.v2) / 2;
  164.   u_len_2 = zoom_factor * (view.u2 - view.u1) / 2;
  165.   v_len_2 = zoom_factor * (view.v2 - view.v1) / 2;
  166.   view.u1 = u_cen - u_len_2;
  167.   view.u2 = u_cen + u_len_2;
  168.   view.v1 = v_cen - v_len_2;
  169.   view.v2 = v_cen + v_len_2;
  170.   lgd_set_view( &view );
  171.   lgd_update_display();
  172.   return(0);
  173. }
  174.   
  175. /*-----------------------------------------------------------------------
  176.  * Function:     gr_redraw
  177.  * Description:  redraws the picture after reading the current values
  178.  *               of the eye, focus, up, and vpw text fields
  179.  * Arguments:    none
  180.  * Returns:      nothing
  181.  */
  182. int
  183. gr_redraw()
  184. {
  185.   lgd_View3 view;
  186.  
  187.   gr_get_eye_display( view.eye );
  188.   gr_get_focus_display( view.focus );
  189.   gr_get_up_display( view.up );
  190.   gr_get_view_plane_window_display( &view.u1, &view.u2, &view.v1, &view.v2 );
  191.   lgd_set_view( &view );
  192.   lgd_update_display();
  193.   return(0);
  194. }
  195.  
  196. int
  197. gr_reset()
  198. {
  199.   lgd_View3 view;
  200.  
  201.   lgd_get_default_view( &view );
  202.   lgd_set_view( &view );
  203.   lgd_update_display();
  204.   return(0);
  205. }
  206.